#!/usr/bin/env python
# -*- coding: UTF-8 -*-

import sys
from time import localtime,strftime

current_nasid=None
count=1
ep_list=["-","-","-","-"]
for line in sys.stdin:
    ll=line.strip().split("\t")
    if len(ll)==5:
        cid,sid,nasid,t,ep=ll
        x=""
        try:
            x=localtime(long(t)/1000)
        except:
            x="00000000"
        day=strftime('%Y%m%d',x)
        if not ep:
            ep="-"

        if current_nasid:
            if current_nasid==nasid:
                count=count+1
                if count ==3:
                    ep_list[count]=ep
                    print "\t".join(ep_list)+"\t"+day

                if count>3:
                    continue
                ep_list[count]=ep

            else:
                if count<3:
                    print "\t".join(ep_list)+"\t"+day
                # ep_list=[cid+"\t"+sid,"-","-","-"]
                count=1

        current_nasid=nasid
        if count==1:
            ep_list=[cid+"\t"+sid,"-","-","-"]
        ep_list[count]=ep

if count<3:
    print "\t".join(ep_list)+"\t"+day